<?php
echo $this->Html->css('controllers/Passports/passport.css?3', array('block' => 'stylesTop'));
echo $this->Html->script('controllers/Passports/passports.js?2', array('block' => 'scriptBottom'));
echo $this->Html->css('controllers/Passports/index.css?2', array('block' => 'stylesTop'));
$appBosch->urlNext = $this->Html->url(array('action' => 'teamsPassportsAjax'));
echo $this->Session->flash(); ?>
    <div class="searchEmp hidden-print">
        <form action="<?php echo $this->Html->url(array('action' => 'passports')); ?>" method="GET">
            <p>
                <label for="moes"><?php echo __('MOE'); ?>:</label><input id="moes" name="moe"
                                                                                style="width: 270px" required/>
            </p>

            <p>
                <label for="areas"><?php echo __('Área'); ?>:</label><input id="areas" name="area"
                                                                               disabled="disabled" style="width: 270px"
                                                                               required/>
            </p>

            <p>
                <label for="lineas"><?php echo __('Línea'); ?>:</label><input id="lineas" name="linea"
                                                                              disabled="disabled" style="width: 270px"
                                                                              required/>
            </p>

            <label for="employees"> <?php echo __('Numero de nomina'); ?> </label>
            <input type="text" class="form-control" id="employees" name="payrolls"
                   placeholder="Ejemplo: 91919191 90909090" required/>
            <input type="submit" id="btnImprimir" class="btn btn-primary" value="<?php echo __("Buscar"); ?>"/>
        </form>
    </div>
    <div id="waiting"><i class="fa fa-spinner fa-spin"></i></div>

    <div class="print-button hidden-print">
        <span class="k-button k-primary"><?php echo __('Imprimir pasaportes'); ?></span>
    </div>
<?php
$hojas = ceil(count($data->records) / 8);
$j = 0;
$m = 0;
for ($k = 1; $k <= $hojas; $k++) { ?>
    <table class="passports" style="page-break-after: always;">
        <?php for (; $j < 8 * $k; $j++) {
            if (isset($data->records[$j]['certs']) && count($data->records[$j]['certs']) != 0) {
                $user = $data->records[$j]['certs'];
                if ($j % 2 == 0) { ?>
                    <tr>
                <?php } ?>
                <td class="passport" style=''>
                    <div class="headPasport">
                        <div>
                            <?php echo $this->Html->image('bosch-logo.png', array('height' => '30px')); ?>
                        </div>
                        <div>
                            <p><?php echo $data->records[$j]['str']['title']; ?></p>
                        </div>
                        <div class="iconCategorization">
                            <i class="<?php echo $data->records[$j]['catIcon']; ?>"
                               style="color: <?php echo $data->records[$j]['catColor']; ?> !important; @media print { color: <?php echo $data->records[$j]['catColor']; ?> !important; }"></i>
                        </div>
                    </div>
                    <div class="bodyPassport">
                        <div>
                            <div class="mla">
                                <?php echo $data->records[$j]['nameLine']; ?>
                            </div>
                            <div class="numNom">
                                <?php echo $user[0]['numNom']; ?>
                            </div>
                        </div>
                        <div class="nomAsc">
                            <?php echo $user[0]['nameAsc']; ?>
                        </div>
                        <div class="tablaCert">
                            <?php if (count($user) > 9) {
                            $length = 18; ?>
                            <table style="width: 50%">
                                <?php } else {
                                $length = 36; ?>
                                <table style="width: 100%">
                                    <?php } ?>
                                    <tr>
                                        <th><?php echo __('Operación'); ?></th>
                                        <th></th>
                                        <th><?php echo __('Fecha'); ?></th>
                                    </tr>
                                    <?php
                                    $i = 0;
                                    if (isset($user[$i])) {
                                        for (; $i < 9; $i++) {
                                            if (isset($user[$i])) { ?>
                                                <tr>
                                                    <td>
                                                        <p class="nameWork"><?php echo $user[$i]['nameWork']; ?></p>
                                                    </td>
                                                    <td>
                                                        <?php if ($user[$i]['sucss'] == '1') { ?>
                                                            <?php echo $this->Html->image('success.png'); ?>
                                                        <?php } elseif ($user[$i]['train'] == '1') { ?>
                                                            <?php echo $this->Html->image('proces.png'); ?>
                                                        <?php } ?>
                                                    </td>
                                                    <td>
                                                        <?php if ($user[$i]['sucss'] == '1') { ?>
                                                            <p class="fechaCert"><?php echo $user[$i]['life']; ?></p>
                                                        <?php } elseif ($user[$i]['train'] == '1') { ?>
                                                            <p class="fechaFinCert"><?php echo $user[$i]['end']; ?></p>
                                                        <?php } ?>
                                                    </td>
                                                </tr>
                                            <?php } else { ?>
                                                <tr>
                                                    <td>&nbsp;</td>
                                                    <td>&nbsp;</td>
                                                    <td>&nbsp;</td>
                                                </tr>
                                            <?php }
                                        }
                                    }
                                    ?>
                                </table>
                                <table>
                                    <?php
                                    if (isset($user[$i])) { ?>
                                        <tr>
                                            <th><?php echo __('Operación'); ?></th>
                                            <th></th>
                                            <th><?php echo __('Fecha'); ?></th>
                                        </tr>
                                        <?php for (; $i < 18; $i++) {
                                            if (isset($user[$i])) { ?>
                                                <tr>
                                                    <td>
                                                        <p class="nameWork"><?php echo $user[$i]['nameWork']; ?></p>
                                                    </td>
                                                    <td>
                                                        <?php if ($user[$i]['sucss'] == '1') { ?>
                                                            <?php echo $this->Html->image('success.png'); ?>
                                                        <?php } elseif ($user[$i]['train'] == '1') { ?>
                                                            <?php echo $this->Html->image('proces.png'); ?>
                                                        <?php } ?>
                                                    </td>
                                                    <td>
                                                        <?php if ($user[$i]['sucss'] == '1') { ?>
                                                            <p class="fechaCert"><?php echo $user[$i]['life']; ?></p>
                                                        <?php } elseif ($user[$i]['train'] == '1') { ?>
                                                            <p class="fechaFinCert"><?php echo $user[$i]['end']; ?></p>
                                                        <?php } ?>
                                                    </td>
                                                </tr>
                                            <?php } else { ?>
                                                <tr>
                                                    <td>&nbsp;</td>
                                                    <td>&nbsp;</td>
                                                    <td>&nbsp;</td>
                                                </tr>
                                            <?php }
                                        }
                                    }
                                    ?>
                                </table>
                        </div>
                        <p class="printDate">
                            Fecha de impresi&oacute;n: <?php echo date('Y-m-d'); ?>
                        </p>
                    </div>
                </td>
                <?php if ($j % 2 != 0) { ?>
                    </tr>
                <?php }
            } else {
                if ($j % 2 == 0) { ?>
                    <tr>
                <?php } ?>
                <td class="passport"></td>
                <?php if ($j % 2 != 0) { ?>
                    </tr>
                <?php }
            }
        } ?>
    </table>
    <table class="backPassports ">
        <?php for (; $m < 8 * $k; $m++) {
            if ($m % 2 == 0) {
                $l = $m + 1; ?>
                <tr>
            <?php } else {
                $l = $m - 1;
            } ?>
            <td class="backPassport">
                <?php if (isset($data->records[$l]['certs']) && count($data->records[$l]['certs']) != 0) { ?>
                <div class="bodyBPassport">
                    <div>
                        <?php echo $data->records[$l]['str']['msg']; ?>
                    </div>
                    <div class="qrcode" data-code="<?php echo $data->records[$l]['urlQR']; ?>"
                         data-color="<?php echo $data->records[$l]['catColor']; ?>">
                    </div>
                    <div>
                        <?php if (isset($data->records[$l]['emi'])) { ?>
                            Elaborado por: <?php echo $data->records[$l]['emi']; ?>
                        <?php } else { ?>
                            &nbsp;
                        <?php } ?>
                    </div>
                    <?php if (isset($data->records[$l]['emi'])) { ?>
                    <div class="bcd kbarcode" data-codeforbar="<?php echo $data->records[$l]['security']; ?>">
                        <?php } else { ?>
                        <div class="bcd">
                            <?php } ?>


                        </div>
                    </div>
                    <div class="footBPassport"><?php echo $data->records[$l]['str']['footer']; ?></div>
                    <?php } else { ?>
                        &nbsp;
                    <?php } ?>
            </td>
            <?php if ($m % 2 != 0) { ?>
                </tr>
            <?php }
        } ?>
    </table>
<?php } ?>


<?php $this->start('jsVars'); ?>
    <script type="text/javascript">
        var appBosch = <?php echo json_encode($appBosch); ?>;

        var urlPassport = '<?php echo $this->Html->url(array('action' => 'passports')); ?>';
        var urlMoes = '<?php echo $this->Html->url(array('controller' => 'Moes', 'action' => 'read')); ?>';
        var urlAreas = '<?php echo $this->Html->url(array('controller' => 'Areas', 'action' => 'getAreasByMoe', '1')); ?>';
        var urlLines = '<?php echo $this->Html->url(array('controller' => 'Lines', 'action' => 'getLinesByArea', '1')); ?>';

        var urlPdf = '<?php echo $this->Html->url(array('action' => 'printPdf')); ?>'
    </script>
<?php $this->end();